define([
    'zepto',
    'underscore',
    'backbone',
    "text!templates/olpay/order.html",
    "text!templates/olpay/bankList.html",
    "wTools"

], function ($, _, Backbone, order, bankList) {
    return Backbone.View.extend({
        $el: $main,
        el: $main0,
        template: _.template(order),
        templateBankList: _.template(bankList),
        events: {
            "tap #detail": "detail",
        },
        initialize: function () {

            if (wData.urlData.token != undefined && wData.urlData.token != "" && wData.urlData.token != null && wData.urlData.token != wData.token) {
                wData.token = wData.urlData.token;
            }
            if (wData.token != undefined && wData.token != "" && wData.token != null) {
                $.cookie("token", wData.token, {path: "/"});
            } else if ($.cookie("token") != undefined && $.cookie("token") != "" && $.cookie("token") != null) {
                wData.token = $.cookie("token");
            } else {
                wData.errorMessage = "操作超时,请重试";
                location.hash = "fail";
            }


            if (!($("#order").length > 0)) {
                if (wData.orderInfo == undefined || wData.orderInfo == '' || wData.orderInfo == null) {
                    var postData = {
                        token: wData.token
                    }, that = this;
                    that.render();
                   /* wAjaxForm("getOrderInfo", "", postData, function (result) {
                        if (result.success == true) {
                            wData.noCard = false;
                            wData.cardList = result.data.qpayCardInfos;
                            wData.orderInfo = result.data.tradeVoucherList[0];
                            wData.orderInfoTouchuan={
                                payerName:"",
                                idNumber:"",
                                phoneNumber:"",
                                payerCardNo:"",
                                cardType:""
                            };
                            if(result.data.buyerInfo!=undefined&&result.data.buyerInfo!=null) {
                                wData.orderInfoTouchuan = result.data.buyerInfo;
                            }
                            console.log(wData.orderInfo)
                            $("#home").append(that.template(wData.orderInfo));
                            that.render();
                            if (!wData.cardList.length > 0) {
                                wData.noCard = true;
                                $("#card").hide();
                                $("#head_back").hide();
                            }
                            if(wData.orderInfoTouchuan.cardType!=""&&wData.orderInfoTouchuan.cardType!=undefined&&wData.orderInfoTouchuan.cardType!=null) {
                                if (wData.orderInfoTouchuan.cardType == "DC") {
                                    $("#cardNo").attr("placeholder", "储蓄卡");
                                } else if (wData.orderInfoTouchuan.cardType == "CC") {
                                    $("#cardNo").attr("placeholder", "信用卡");
                                }
                            }
                        }
                        else {
                            wTips(result.message);
                        }
                    });*/
                } else {
                    $("#home").append(this.templateOrder(wData.orderInfo));
                    if(wData.orderInfoTouchuan.cardType!=""&&wData.orderInfoTouchuan.cardType!=undefined&&wData.orderInfoTouchuan.cardType!=null) {
                        if (wData.orderInfoTouchuan.cardType == "DC") {
                            $("#cardNo").attr("placeholder", "储蓄卡");
                        } else if (wData.orderInfoTouchuan.cardType == "CC") {
                            $("#cardNo").attr("placeholder", "信用卡");
                        }
                    }
                }

            } else {

                this.render();
                if (wData.noCard) {
                    $("#card").hide();
                    $("#head_back").hide();
                }
                if(wData.orderInfoTouchuan.cardType!=""&&wData.orderInfoTouchuan.cardType!=undefined&&wData.orderInfoTouchuan.cardType!=null) {
                    if (wData.orderInfoTouchuan.cardType == "DC") {
                        $("#cardNo").attr("placeholder", "储蓄卡");
                    } else if (wData.orderInfoTouchuan.cardType == "CC") {
                        $("#cardNo").attr("placeholder", "信用卡");
                    }
                }
            }
            wData.tradeVoucherLength = 5;

        },
        render: function (data) {
            var html = this.templateBankList(data);
            this.$el.html(html);
        },
        destroy: function () {
            this.undelegateEvents();
            this.$el.html("");
            $("#head_back").show();
            delete this;
        }
    });
});